/**
 * Created by hiibook on 2017/6/16.
 */
var wechatMsgConstruct = require('./wechatMsgConstruct');
module.exports = function (req, res, next) {
    console.log('查看个人信息');
    if (req.wechatMsg.MsgType == "text") {
        switch (true) {
            case /我的信息/.test(req.wechatMsg.Content):
            case /流量/.test(req.wechatMsg.Content):
            case /剩余流量/.test(req.wechatMsg.Content):
            case /个人信息/.test(req.wechatMsg.Content):
            case /个人资料/.test(req.wechatMsg.Content):
            case /查看密码/.test(req.wechatMsg.Content):
                if (req.wechatUserStatus) {
                    console.log('接受命令');
                    getMyInfo(req, res, next);
                } else {
                    var chat = {
                        Type: "text",
                        Content: require('../config/config').unRegistered
                    };
                    // 最后一步需要信息,并关闭数据库连接
                    req.mysqlConnection.end();
                    res.send(wechatMsgConstruct(req.wechatMsg, chat));
                }

                break;
            default:
                next();
                break;
        }
    } else {
        next()
    }

    function getMyInfo(req, res, next) {
        var chat = {
            Type: "text",
            Content:
            "端口号:" + req.wechatUserInfo.id +"\n"+
            "密码:"+req.wechatUserInfo.pass+"\n"+
            "总流量:"+(req.wechatUserInfo.transfer_enable/1073741824).toFixed(2)+"G\n"+
            "已使用:"+((req.wechatUserInfo.up_Data+req.wechatUserInfo.down_date)/1073741824).toFixed(2)+"G\n"
        };
        if(req.wechatUserInfo.is_manager == 1){
            chat.Content += "您是我们的管理员\n"
        }
        if(req.wechatUserInfo.available == 0){
            chat.Content += "您的帐号被禁用了，请联系管理员\n"
        }
        // 最后一步需要信息,并关闭数据库连接
        req.mysqlConnection.end();
        res.send(wechatMsgConstruct(req.wechatMsg, chat));
    }


};